<?php

namespace App\Http\Controllers\Client\Common;

use App\Models\Ass;
use App\Models\AssMember;
use App\Models\Member\Follow;
use App\Models\Member\Member;
use App\Http\Controllers\RootController as Controller;
use App\Models\Obj;
use App\Services\Com\StatisticsService;
use Illuminate\Http\Request;

class ObjController extends Controller
{
    public function handle(Request $request)
    {
        $param['obj_id'] = $request->get('obj_id');

        $rules    = [
            'obj_id' => 'required',
        ];
        $messages = [
            'obj_id.required'                   => '请输入帮扶人id',
        ];

        if (true !== ($error = $this->validator($param, $rules, $messages)))
        {
            return $this->failure($error, 'VALIDATION_FAIL');
        }


        $obj = Obj::with('nation')->find($param['obj_id'])->toArray();

        $assList = Ass::orderBy('id', 'desc')->with('assMembers.member')->where('type', 1)->where('obj_id', $param['obj_id'])->get()->toArray();

        $obj['ass_list'] = $assList;
        $obj['ass_total'] = count($assList);

        return $this->success($obj);
    }
}
